package q1.project.common.config;

import jakarta.annotation.Resource;
import java.util.concurrent.Executor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 异步支持配置类 仅负责启用 @Async 支持，并将默认执行器指向 ThreadPoolConfig 中配置的 taskExecutor
 *
 * @author Q1 Team
 * @version 1.0
 */
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

  // 注入由 ThreadPoolConfig 配置的线程池
  @Resource
  @Qualifier("taskExecutor")
  private Executor taskExecutor;

  @Override
  public Executor getAsyncExecutor() {
    return taskExecutor;
  }

  @Override
  public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
    return new SimpleAsyncUncaughtExceptionHandler();
  }
}
